import api from '@/store/api';

export const usePciStore = defineStore('PciStore', () => {
  const pciInfo = ref([] as Record<string, any>[]);
  const setPciInfo = (Info: Record<string, any>[]) => {
    pciInfo.value = Info;
  };
  const getPciInfo = async () => {
    await api
      .get('/redfish/v1/Systems/system/Oem')
      .then(
        ({
          data: {
            Oem: { PCIDeviceInformation },
          },
        }) => {
          const PCIInfoList = PCIDeviceInformation.map((item: any) => {
            return { PCIInfo: item };
          });
          setPciInfo(PCIInfoList);
        },
      )
      .catch((err) => {
        throw err;
      });
  };

  return { pciInfo, setPciInfo, getPciInfo };
});
